
from lib.api import *
import re
from lib.urls import *


def suite_setup():
    INFO('返回token')
    global auth_token
    auth_token = am.getToken()




class API_3026:
    name = 'API_3026'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName正确，locationId不填，status正确")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[18][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3027:
    name = 'API_3027'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token过期，deviceName正确，locationId不填，status正确")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMjAwNjg2NCwidXNlcklkIjoieXp5YWRtaW4ifQ.-fJYSIJdfbiSabU71x9nbb2n2qbl8IM_s6xk0LuNVfk'
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3028:
    name = 'API_3028'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token 为空，deviceName正确，locationId不填，status正确")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 # headers={
                                 #     "auth-token": auth_token
                                 # },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3029:
    name = 'API_3029'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName正确，locationId:349 正确，status正确")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0,
            'locationId':349
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[18][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3030:
    name = 'API_3030'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName正确，status正确，locationId:347 错误,虽然347存在，但不是目标location")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0,
            'locationId':347
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3031:
    name = 'API_3031'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName：AFC001111 错误，locationId不填，status正确")
        urlpara = {
            'deviceName':'AFC001111',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3032:
    name = 'API_3032'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName 为空，locationId不填，status正确")
        urlpara = {
            # 'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':0
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3033:
    name = 'API_3033'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName正确，locationId不填，status：2 错误")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22',
            'status':2
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])


class API_3034:
    name = 'API_3034'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：AFC控制接口 测试     #3.3')
        INFO("前置条件：token正确，deviceName正确，locationId不填，status 为空")
        urlpara = {
            'deviceName':'AFC001',
            'startTime':'2021-06-08 22:22:22'
            # 'status':2
        }
        response = requests.post(url_Target_Address+url_Control_AFCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[19][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致', result==[])









